/**
 *====================================================
 * 文件名称: FinanceAbnormalActionApiImpl.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2015年11月21日			chenxy(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 */
package com.yuexunit.finance.project.action.v1;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.BooleanUtils;

import com.yuexunit.core.BusinessException;
import com.yuexunit.core.ConfigPropertites;
import com.yuexunit.finance.common.util.BeanUtils;
import com.yuexunit.finance.common.util.DateUtils;
import com.yuexunit.finance.common.util.LongUtils;
import com.yuexunit.finance.context.FinanceBaseAction;
import com.yuexunit.finance.context.FinanceLetterBlockingQueue;
import com.yuexunit.finance.context.FinanceSessionContext;
import com.yuexunit.finance.member.entity.LogisticsCompanyEntity;
import com.yuexunit.finance.member.service.LogisticsCompanyService;
import com.yuexunit.finance.project.AbnormalExpenseSource;
import com.yuexunit.finance.project.action.v1.dto.AbnormalCastor;
import com.yuexunit.finance.project.action.v1.dto.BulkstockCastor;
import com.yuexunit.finance.project.action.v1.dto.FinanceLoanCastor;
import com.yuexunit.finance.project.action.v1.dto.FinanceProcessCastor;
import com.yuexunit.finance.project.action.v1.model.AbnormalBlame;
import com.yuexunit.finance.project.action.v1.model.AbnormalCasualty;
import com.yuexunit.finance.project.action.v1.model.AbnormalCorrective;
import com.yuexunit.finance.project.action.v1.model.AbnormalEquipment;
import com.yuexunit.finance.project.action.v1.model.AbnormalExpense;
import com.yuexunit.finance.project.action.v1.model.AbnormalRisk;
import com.yuexunit.finance.project.action.v1.model.AbnormalSurvey;
import com.yuexunit.finance.project.action.v1.model.input.AbnormalParams;
import com.yuexunit.finance.project.action.v1.model.input.AbnormalUpdateParams;
import com.yuexunit.finance.project.action.v1.model.output.AbnormalBlameDetail;
import com.yuexunit.finance.project.action.v1.model.output.AbnormalCasualtyDetail;
import com.yuexunit.finance.project.action.v1.model.output.AbnormalCorrectiveDetail;
import com.yuexunit.finance.project.action.v1.model.output.AbnormalDetail;
import com.yuexunit.finance.project.action.v1.model.output.AbnormalEquipmentDetail;
import com.yuexunit.finance.project.action.v1.model.output.AbnormalExpenseDetail;
import com.yuexunit.finance.project.action.v1.model.output.AbnormalInventoryDetail;
import com.yuexunit.finance.project.action.v1.model.output.AbnormalLineInfo;
import com.yuexunit.finance.project.action.v1.model.output.AbnormalRiskDetail;
import com.yuexunit.finance.project.action.v1.model.output.AbnormalSurveyDetail;
import com.yuexunit.finance.project.action.v1.model.output.AbnormalTrackDetail;
import com.yuexunit.finance.project.action.v1.model.output.DetainedApplicationDetail;
import com.yuexunit.finance.project.action.v1.model.output.DetainedApplicationLineInfo;
import com.yuexunit.finance.project.entity.AbnormalBlameEntity;
import com.yuexunit.finance.project.entity.AbnormalCasualtyEntity;
import com.yuexunit.finance.project.entity.AbnormalCorrectiveEntity;
import com.yuexunit.finance.project.entity.AbnormalEntity;
import com.yuexunit.finance.project.entity.AbnormalEquipmentEntity;
import com.yuexunit.finance.project.entity.AbnormalExpenseEntity;
import com.yuexunit.finance.project.entity.AbnormalInventoryEntity;
import com.yuexunit.finance.project.entity.AbnormalRiskEntity;
import com.yuexunit.finance.project.entity.AbnormalSurveyEntity;
import com.yuexunit.finance.project.entity.AbnormalTrackEntity;
import com.yuexunit.finance.project.entity.ContainerBulkstockEntity;
import com.yuexunit.finance.project.entity.ContainerInventoryEntity;
import com.yuexunit.finance.project.entity.ContainerInventoryRelieveEntity;
import com.yuexunit.finance.project.entity.ContainerInventorySignEntity;
import com.yuexunit.finance.project.entity.ContainerInventoryTallyEntity;
import com.yuexunit.finance.project.entity.DetainedApplicationEntity;
import com.yuexunit.finance.project.entity.DetainedInventoryEntity;
import com.yuexunit.finance.project.entity.FinanceApplicationEntity;
import com.yuexunit.finance.project.entity.FinanceBulkstockEntity;
import com.yuexunit.finance.project.entity.FinanceContainerEntity;
import com.yuexunit.finance.project.entity.FinanceMoneyStatementEntity;
import com.yuexunit.finance.project.entity.FinanceProcessEntity;
import com.yuexunit.finance.project.entity.TallyingEntity;
import com.yuexunit.finance.project.entity.lexicon.AbnormalResultEnum;
import com.yuexunit.finance.project.entity.lexicon.AbnormalStateEnum;
import com.yuexunit.finance.project.entity.lexicon.AbnormalTypeEnum;
import com.yuexunit.finance.project.entity.lexicon.ApplicationSimpleStateEnum;
import com.yuexunit.finance.project.entity.lexicon.BadassetsStateEnum;
import com.yuexunit.finance.project.entity.lexicon.HandleStateEnum;
import com.yuexunit.finance.project.entity.lexicon.SettlementStateEnum;
import com.yuexunit.finance.project.entity.lexicon.SupervisionStateEnum;
import com.yuexunit.finance.project.service.AbnormalBlameService;
import com.yuexunit.finance.project.service.AbnormalCasualtyService;
import com.yuexunit.finance.project.service.AbnormalCorrectiveService;
import com.yuexunit.finance.project.service.AbnormalEquipmentService;
import com.yuexunit.finance.project.service.AbnormalExpenseService;
import com.yuexunit.finance.project.service.AbnormalInventoryService;
import com.yuexunit.finance.project.service.AbnormalRiskService;
import com.yuexunit.finance.project.service.AbnormalService;
import com.yuexunit.finance.project.service.AbnormalSurveyService;
import com.yuexunit.finance.project.service.AbnormalTrackService;
import com.yuexunit.finance.project.service.DetainedApplicationService;
import com.yuexunit.finance.project.service.DetainedInventoryService;
import com.yuexunit.finance.project.service.FinanceMoneyStatementService;
import com.yuexunit.inject.ComponentFactory;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.annotation.Transactional;
import com.yuexunit.util.DateUtil;

/**
 * @ClassName: FinanceAbnormalActionApiImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author chenxy
 * @date 2015年11月21日 下午5:37:00
 */
@Implements(FinanceAbnormalActionApi.class)
public class FinanceAbnormalActionApiImpl extends FinanceBaseAction implements FinanceAbnormalActionApi {

	private DetainedApplicationService detainedApplicationService = ComponentFactory.loadClass(DetainedApplicationService.class);

	private DetainedInventoryService detainedInventoryService = ComponentFactory.loadClass(DetainedInventoryService.class);

	private AbnormalService abnormalService = ComponentFactory.loadClass(AbnormalService.class);

	private AbnormalInventoryService abnormalInventoryService = ComponentFactory.loadClass(AbnormalInventoryService.class);

	private AbnormalSurveyService abnormalSurveyService = ComponentFactory.loadClass(AbnormalSurveyService.class);

	private AbnormalBlameService abnormalBlameService = ComponentFactory.loadClass(AbnormalBlameService.class);

	private AbnormalCorrectiveService abnormalCorrectiveService = ComponentFactory.loadClass(AbnormalCorrectiveService.class);

	private AbnormalCasualtyService abnormalCasualtyService = ComponentFactory.loadClass(AbnormalCasualtyService.class);

	private AbnormalEquipmentService abnormalEquipmentService = ComponentFactory.loadClass(AbnormalEquipmentService.class);

	private AbnormalExpenseService abnormalExpenseService = ComponentFactory.loadClass(AbnormalExpenseService.class);

	private AbnormalTrackService abnormalTrackService = ComponentFactory.loadClass(AbnormalTrackService.class);

	private AbnormalRiskService abnormalRiskService = ComponentFactory.loadClass(AbnormalRiskService.class);

	private FinanceMoneyStatementService financeMoneyStatementService = ComponentFactory.loadClass(FinanceMoneyStatementService.class);

	@Transactional
	@Override
	public String createDetainedApplication(Long financeId, Integer applicantReson, String remark, Long[] inventoryIds) {
		if (inventoryIds == null || inventoryIds.length <= 0) {
			throw new BusinessException("货箱信息不能为空");
		}
		FinanceApplicationEntity finance = financeApplicationService.inquireFinanceApplicationEntity(financeId);
		DetainedApplicationEntity detained = new DetainedApplicationEntity();
		detained.setApplicantReson(applicantReson);
		detained.setFinanceId(finance.getFinanceId());
		detained.setFinanceNumber(finance.getFinanceNumber());
		detained.setEnterpriseId(finance.getEnterpriseId());
		detained.setEnterpriseName(finance.getEnterpriseName());
		detained.setApplicant(FinanceSessionContext.getAccountFullName());
		detained.setApplicantId(FinanceSessionContext.getAccountId());
		if (FinanceSessionContext.isEnterprise()) {
			detained.setApplicantDepartment(FinanceSessionContext.getEnterpriseName());
		} else if (FinanceSessionContext.isLogistics()) {
			LogisticsCompanyService logisticsCompanyService = ComponentFactory.loadClass(LogisticsCompanyService.class);
			LogisticsCompanyEntity companyDetail = logisticsCompanyService.inquireLogisticsCompanyDetail(FinanceSessionContext.getCompanyId());
			detained.setApplicantDepartment(companyDetail.getCompanyName());
		} else {
			detained.setApplicantDepartment(ConfigPropertites.getProperties("platform.name"));
		}
		detained.setRemark(remark);
		detained.setDetainedApplicationDateTime(DateUtil.now());
		Long detainedId = detainedApplicationService.createDetainedApplication(detained);

		for (Long inventoryId : inventoryIds) {
			ContainerInventoryEntity cie = containerInventoryService.inquireContainerInventory(inventoryId);
			if (cie.getDetainedState()) {
				throw new BusinessException("货箱已被扣押");
			}
			DetainedInventoryEntity inventory = new DetainedInventoryEntity();
			inventory.setDetainedId(detainedId);
			inventory.setInventoryId(cie.getInventoryId());
			detainedInventoryService.createDetainedInventory(inventory);

			cie.setDetainedState(Boolean.TRUE);
			containerInventoryService.renovateContainerInventory(cie);
		}
		// 发送消息
		FinanceLetterBlockingQueue.putEnterpriseExceptionLetter(getFinanceEnterpriseId(detained.getFinanceId()), "扣货申请", "exception.detained", detained.getFinanceNumber(), DateUtils.getCurrentLinkedDateTime(), detained.getDetainedNumber());
		return detainedId.toString();
	}

	@Transactional
	@Override
	public void cancelDetainedApplication(Long detainedId) {
		DetainedApplicationEntity detained = detainedApplicationService.inquireDetainedApplication(detainedId);
		detained.setApplicationState(ApplicationSimpleStateEnum.CANCEL);
		detainedApplicationService.renovateDetainedApplication(detained);
		// 解除箱扣货状态
		List<Long> inventoryIds = detainedInventoryService.inquireGroupDetainedInventoryIds(detainedId);
		List<ContainerInventoryEntity> containers = containerInventoryService.inquireContainerInventoryList(inventoryIds.toArray(new Long[inventoryIds.size()]));
		for (ContainerInventoryEntity container : containers) {
			container.setDetainedState(Boolean.FALSE);
			containerInventoryService.renovateContainerInventory(container);
		}
	}

	@Transactional
	@Override
	public void consentDetainedApplication(Long detainedId, String auditRemark) {
		DetainedApplicationEntity detained = detainedApplicationService.inquireDetainedApplication(detainedId);
		detained.setApplicationState(ApplicationSimpleStateEnum.AGREE);
		detained.setAuditRemark(auditRemark);
		detained.setAuditor(FinanceSessionContext.getAccountFullName());
		detained.setAuditorId(FinanceSessionContext.getAccountId());
		detained.setAuditDateTime(DateUtils.now());
		detained.setDetainedApplicationDateTime(null);
		detainedApplicationService.renovateDetainedApplication(detained);

		List<DetainedInventoryEntity> detainedInventories = detainedInventoryService.inquireDetainedInventoryList(detainedId);
		List<ContainerInventoryEntity> inventories = new ArrayList<>();
		for (DetainedInventoryEntity die : detainedInventories) {
			ContainerInventoryEntity inventory = containerInventoryService.inquireContainerInventory(die.getInventoryId());
			inventory.setAbnormal(false);
			inventory.setDetainedState(Boolean.TRUE);
			containerInventoryService.renovateContainerInventory(inventory);
			inventories.add(inventory);
		}
		financeBulkstockService.calculateIncustodyFinanceBulkstock(detained.getFinanceId());
		financeBulkstockService.calculateAbnormalFinanceBulkstock(detained.getFinanceId());

		// 异常处理
		AbnormalEntity abnormal = AbnormalCastor.fromDetainedApplication(detained, inventories);
		Long abnormalId = abnormalService.createAbnormal(abnormal);
		AbnormalInventoryEntity abnormalInventory = new AbnormalInventoryEntity();
		for (ContainerInventoryEntity inventory : inventories) {
			abnormalInventory.setInventoryId(inventory.getInventoryId());
			abnormalInventory.setAbnormalId(abnormalId);
			abnormalInventoryService.createAbnormalInventory(abnormalInventory);
		}
	}

	@Transactional
	@Override
	public void opposeDetainedApplication(Long detainedId, Integer disagreeReson, String auditRemark) {
		DetainedApplicationEntity detained = detainedApplicationService.inquireDetainedApplication(detainedId);
		detained.setApplicationState(ApplicationSimpleStateEnum.DISAGREE);
		detained.setDisagreeReson(disagreeReson);
		detained.setAuditRemark(auditRemark);
		detainedApplicationService.renovateDetainedApplication(detained);
		// 解除箱扣货状态
		List<Long> inventoryIds = detainedInventoryService.inquireGroupDetainedInventoryIds(detainedId);
		List<ContainerInventoryEntity> containers = containerInventoryService.inquireContainerInventoryList(inventoryIds.toArray(new Long[inventoryIds.size()]));
		for (ContainerInventoryEntity container : containers) {
			container.setDetainedState(Boolean.FALSE);
			containerInventoryService.renovateContainerInventory(container);
		}
	}

	@Override
	public DetainedApplicationDetail inquireDetainedApplicationDetail(Long detainedId) {
		DetainedApplicationEntity detainedApplication = detainedApplicationService.inquireDetainedApplication(detainedId);
		return AbnormalCastor.toDetainedApplicationDetail(detainedApplication);
	}

	@Override
	public PageList<DetainedApplicationLineInfo> inquireDetainedApplicationPageList(Long[] detainedIds, Long enterpriseId, Long financeId, Integer applicationState, PageCriteria page) {
		if (FinanceSessionContext.isEnterprise()) {
			enterpriseId = FinanceSessionContext.getEnterpriseId();
		}
		ApplicationSimpleStateEnum _state = null;
		if (applicationState != null) {
			_state = ApplicationSimpleStateEnum.valueOf(applicationState);
		}
		PageList<DetainedApplicationEntity> pages = detainedApplicationService.inquireDetainedApplicationPageList(detainedIds, financeId, enterpriseId, _state, page);
		PageList<DetainedApplicationLineInfo> results = new PageList<>(page, pages.getTotalRecordCount());
		for (DetainedApplicationEntity dae : pages) {
			results.add(AbnormalCastor.toDetainedApplicationLineInfo(dae));
		}
		return results;
	}

	// ==============================================================================================================================================================//
	/** 责任人处置 设备异常 人员伤亡 */
	private AbnormalExpenseEntity createAbnormalSourceExpense(AbnormalExpenseSource source) {
		AbnormalExpenseEntity entity = new AbnormalExpenseEntity();
		entity.setAbnormalId(source.getAbnormalId());
		entity.setExpenditure(source.getExpenditure());
		entity.setAbnormalAmount(source.getAbnormalAmount());
		entity.setCreateDateTime(source.getCreateDateTime());
		entity.setReportor(source.getReportor());
		entity.setAuthenticatId(source.getAuthenticatId());
		entity.setAuthenticator(source.getAuthenticator());
		entity.setAuthenticatState(source.getAuthenticatState());
		entity.setAuthenticatDateTime(source.getAuthenticatDateTime());
		entity.setAbnormalSource(source.getAbnormalSource());
		entity.setAbnormalSourceId(source.getAbnormalSourceId());

		entity.setReceiptId(source.getReceiptId());
		entity.setReceiptType(source.getReceiptType());
		entity.setReceiptTenantId(source.getReceiptTenantId());
		entity.setReceiptName(source.getReceiptName());
		entity.setDisbursementId(source.getDisbursementId());
		entity.setDisbursementType(source.getDisbursementType());
		entity.setDisbursementTenantId(source.getDisbursementTenantId());
		entity.setDisbursementName(source.getDisbursementName());

		entity.setPaymentDate(DateUtil.nowDate());
		abnormalExpenseService.createAbnormalExpense(entity);

		// 生成收付款单
		AbnormalEntity abnormal = abnormalService.inquireAbnormal(entity.getAbnormalId());
		FinanceMoneyStatementEntity moneyEntity = FinanceLoanCastor.fromAbnormalExpense(abnormal, entity);
		financeMoneyStatementService.createFinanceMoneyStatement(moneyEntity);

		return entity;
	}

	@Override
	public AbnormalDetail inquirePreTallyAbnormalInventory(Long inventoryId) {
		ContainerInventoryEntity inventory = containerInventoryService.inquireContainerInventory(inventoryId);
		TallyingEntity tallying = tallyingService.inquireTallying(inventory.getTallyingId());
		AbnormalEntity abnormal = AbnormalCastor.fromTally(tallying, new Long[] { inventoryId });

		AbnormalDetail abnormalDetail = new AbnormalDetail();
		BeanUtils.copyProperties(abnormal, abnormalDetail);
		abnormalDetail.setAbnormalState(abnormal.getAbnormalState().ordinal());
		abnormalDetail.setAbnormalType(abnormal.getAbnormalType().ordinal());
		abnormalDetail.setHandleState(HandleStateEnum.WAIT_HANDLE.ordinal());

		ContainerInventoryTallyEntity inventoryTally = containerInventoryTallyService.inquireContainerInventoryTally(inventoryId);
		AbnormalInventoryDetail abnormalInventoryDetail = new AbnormalInventoryDetail();
		abnormalInventoryDetail.setInventoryId(inventoryId);
		if (inventoryTally != null) {
			abnormalInventoryDetail.setAbnormalFile(inventoryTally.getTallyExAbnormalFile());
			abnormalInventoryDetail.setSoundRecorde(inventoryTally.getTallyExSoundRecorde());
		}
		abnormalInventoryDetail.setContainerInventory(BulkstockCastor.toContainerInventory(inventory, Boolean.FALSE));

		abnormalDetail.getAbnormalInventories().add(abnormalInventoryDetail);
		return abnormalDetail;
	}

	@Override
	public AbnormalDetail inquirePreDeliveryAbnormalInventory(Long inventoryId) {
		ContainerInventoryEntity inventory = containerInventoryService.inquireContainerInventory(inventoryId);
		ContainerInventorySignEntity inventorySign = containerInventorySignService.inquireContainerInventorySign(inventoryId);
		AbnormalEntity abnormal = AbnormalCastor.fromDeliveryInventory(inventorySign, inventory);

		AbnormalDetail abnormalDetail = new AbnormalDetail();
		BeanUtils.copyProperties(abnormal, abnormalDetail);
		abnormalDetail.setAbnormalState(abnormal.getAbnormalState().ordinal());
		abnormalDetail.setAbnormalType(abnormal.getAbnormalType().ordinal());
		abnormalDetail.setHandleState(HandleStateEnum.WAIT_HANDLE.ordinal());

		AbnormalInventoryDetail abnormalInventoryDetail = new AbnormalInventoryDetail();
		abnormalInventoryDetail.setInventoryId(inventoryId);
		if (inventorySign != null) {
			abnormalInventoryDetail.setAbnormalFile(inventorySign.getSignAbnormalFile());
			abnormalInventoryDetail.setSoundRecorde(inventorySign.getSignSoundRecorde());
		}
		abnormalInventoryDetail.setContainerInventory(BulkstockCastor.toContainerInventory(inventory, Boolean.FALSE));

		abnormalDetail.getAbnormalInventories().add(abnormalInventoryDetail);
		return abnormalDetail;
	}

	@Transactional
	@Override
	public String createAbnormal(AbnormalParams params) {
		AbnormalEntity abnormal = new AbnormalEntity();
		BeanUtils.copyProperties(params, abnormal);
		abnormal.setAbnormalState(AbnormalStateEnum.valueOf(params.getAbnormalState()));
		abnormal.setAbnormalType(AbnormalTypeEnum.valueOf(params.getAbnormalType()));
		abnormal.setHandleState(HandleStateEnum.WAIT_HANDLE);
		abnormal.setRiskEnabled(BooleanUtils.toBoolean(params.getRiskEnabled()));
		Long abnormalId = abnormalService.createAbnormal(abnormal);

		if (AbnormalTypeEnum.TALLY == abnormal.getAbnormalType()) { // 理货异常
			for (Long inventoryId : params.getInventoryId()) {
				ContainerInventoryTallyEntity inventoryTally = containerInventoryTallyService.inquireContainerInventoryTally(inventoryId);
				AbnormalInventoryEntity abnormalInventory = new AbnormalInventoryEntity();
				abnormalInventory.setInventoryId(inventoryId);
				abnormalInventory.setAbnormalId(abnormal.getAbnormalId());
				abnormalInventory.setAbnormalResult(AbnormalResultEnum.UNKNOWN);
				abnormalInventory.setAbnormalFile(inventoryTally.getTallyExAbnormalFile());
				abnormalInventory.setSoundRecorde(inventoryTally.getTallyExSoundRecorde());
				abnormalInventoryService.createAbnormalInventory(abnormalInventory);
			}
		} else if (AbnormalTypeEnum.SIGN == abnormal.getAbnormalType()) { // 签收异常
			for (Long inventoryId : params.getInventoryId()) {
				ContainerInventorySignEntity inventorySign = containerInventorySignService.inquireContainerInventorySign(inventoryId);
				AbnormalInventoryEntity abnormalInventory = new AbnormalInventoryEntity();
				abnormalInventory.setInventoryId(inventoryId);
				abnormalInventory.setAbnormalId(abnormal.getAbnormalId());
				abnormalInventory.setAbnormalResult(AbnormalResultEnum.UNKNOWN);
				if (inventorySign != null) {
					abnormalInventory.setAbnormalFile(inventorySign.getSignAbnormalFile());
					abnormalInventory.setSoundRecorde(inventorySign.getSignSoundRecorde());
				}
				abnormalInventoryService.createAbnormalInventory(abnormalInventory);
			}
		} else {
			for (Long inventoryId : params.getInventoryId()) {
				AbnormalInventoryEntity abnormalInventory = new AbnormalInventoryEntity();
				abnormalInventory.setInventoryId(inventoryId);
				abnormalInventory.setAbnormalId(abnormal.getAbnormalId());
				abnormalInventory.setAbnormalResult(AbnormalResultEnum.UNKNOWN);
				abnormalInventoryService.createAbnormalInventory(abnormalInventory);
			}
		}
		// 发送消息
		FinanceLetterBlockingQueue.putEnterpriseExceptionLetter(getFinanceEnterpriseId(abnormal.getFinanceId()), "异常处理", "exception.abnormal", abnormal.getFinanceNumber(), DateUtils.getCurrentLinkedDateTime(), abnormal.getAbnormalNumber());
		return abnormalId.toString();
	}

	@Transactional
	@Override
	public void updateAbnormal(AbnormalUpdateParams params) {
		AbnormalEntity abnormal = abnormalService.inquireAbnormal(params.getAbnormalId());
		if (HandleStateEnum.WAIT_HANDLE != abnormal.getHandleState()) {
			throw new BusinessException("异常处理已经受理,不允许修改");
		}
		AbnormalEntity entity = AbnormalCastor.fromAbnormal(params);
		abnormalService.updateAbnormal(entity);
	}

	@Transactional
	@Override
	public void confirmAbnormal(Long abnormalId) {
		AbnormalEntity abnormal = abnormalService.inquireAbnormal(abnormalId);
		if (HandleStateEnum.WAIT_HANDLE != abnormal.getHandleState()) {
			throw new BusinessException("异常处理已经受理");
		}
		abnormal.setHandleState(HandleStateEnum.ACCEPT);
		// 发送消息
		FinanceLetterBlockingQueue.putEnterpriseExceptionLetter(getFinanceEnterpriseId(abnormal.getFinanceId()), "异常处理", "exception.abnormal.accept", abnormal.getAbnormalNumber(), DateUtils.getCurrentLinkedDateTime());
		abnormalService.renovateAbnormal(abnormal);
	}

	@Transactional
	@Override
	public void processAbnormal(Long abnormalId) {
		AbnormalEntity abnormal = abnormalService.inquireAbnormal(abnormalId);
		if (HandleStateEnum.ACCEPT != abnormal.getHandleState()) {
			throw new BusinessException("异常处理已经受理");
		}
		abnormal.setHandleState(HandleStateEnum.INHANDLE);
		// 发送消息
		FinanceLetterBlockingQueue.putEnterpriseExceptionLetter(getFinanceEnterpriseId(abnormal.getFinanceId()), "异常处理", "exception.abnormal.inhandle", abnormal.getAbnormalNumber(), DateUtils.getCurrentLinkedDateTime());
		abnormalService.renovateAbnormal(abnormal);
	}

	@Transactional
	@Override
	public void finishAbnormal(Long abnormalId) {
		AbnormalEntity abnormal = abnormalService.inquireAbnormal(abnormalId);
		if (HandleStateEnum.INHANDLE != abnormal.getHandleState()) {
			throw new BusinessException("异常处理已经受理");
		}
		abnormal.setHandleState(HandleStateEnum.FINISHED);
		// 发送消息
		FinanceLetterBlockingQueue.putEnterpriseExceptionLetter(getFinanceEnterpriseId(abnormal.getFinanceId()), "异常处理", "exception.abnormal.finished", abnormal.getAbnormalNumber(), DateUtils.getCurrentLinkedDateTime());
		abnormalService.renovateAbnormal(abnormal);
	}

	@Transactional
	@Override
	public String createAbnormalSurvey(AbnormalSurvey params) {
		AbnormalSurveyEntity entity = AbnormalCastor.fromAbnormalSurvey(params);
		abnormalSurveyService.createAbnormalSurvey(entity);
		return entity.getAbnormalSurveyId().toString();
	}

	@Transactional
	@Override
	public void consentAbnormalSurvey(Long abnormalSurveyId) {
		AbnormalSurveyEntity persist = abnormalSurveyService.inquireAbnormalSurvey(abnormalSurveyId);
		confirmAuthenticat(persist);
		abnormalSurveyService.renovateAbnormalSurvey(persist);
	}

	@Override
	public AbnormalSurveyDetail inquireAbnormalSurveyDetail(Long abnormalSurveyId) {
		AbnormalSurveyEntity abnormalSurvey = abnormalSurveyService.inquireAbnormalSurvey(abnormalSurveyId);
		return AbnormalCastor.toAbnormalSurvey(abnormalSurvey);
	}

	@Transactional
	@Override
	public String createAbnormalBlame(AbnormalBlame params) {
		AbnormalBlameEntity entity = AbnormalCastor.fromAbnormalBlame(params);
		abnormalBlameService.createAbnormalBlame(entity);
		return entity.getAbnormalBlameId().toString();
	}

	@Transactional
	@Override
	public void consentAbnormalBlame(Long abnormalBlameId) {
		AbnormalBlameEntity persist = abnormalBlameService.inquireAbnormalBlame(abnormalBlameId);
		confirmAuthenticat(persist);

		AbnormalExpenseEntity expense = createAbnormalSourceExpense(persist);
		persist.setVoucher(expense.getVoucher());
		abnormalBlameService.renovateAbnormalBlame(persist);
	}

	@Override
	public AbnormalBlameDetail inquireAbnormalBlameDetail(Long abnormalBlameId) {
		AbnormalBlameEntity abnormalBlame = abnormalBlameService.inquireAbnormalBlame(abnormalBlameId);
		return AbnormalCastor.toAbnormalBlame(abnormalBlame);
	}

	@Transactional
	@Override
	public String createAbnormalCorrective(AbnormalCorrective params) {
		AbnormalCorrectiveEntity entity = AbnormalCastor.fromAbnormalCorrective(params);
		abnormalCorrectiveService.createAbnormalCorrective(entity);
		return entity.getAbnormalCorrectiveId().toString();
	}

	@Transactional
	@Override
	public void consentAbnormalCorrective(Long abnormalCorrectiveId) {
		AbnormalCorrectiveEntity persist = abnormalCorrectiveService.inquireAbnormalCorrective(abnormalCorrectiveId);
		confirmAuthenticat(persist);
		abnormalCorrectiveService.renovateAbnormalCorrective(persist);
	}

	@Override
	public AbnormalCorrectiveDetail inquireAbnormalCorrectiveDetail(Long abnormalCorrectiveId) {
		AbnormalCorrectiveEntity abnormalCorrective = abnormalCorrectiveService.inquireAbnormalCorrective(abnormalCorrectiveId);
		return AbnormalCastor.toAbnormalCorrective(abnormalCorrective);
	}

	@Transactional
	@Override
	public String createAbnormalCasualty(AbnormalCasualty params) {
		AbnormalCasualtyEntity entity = AbnormalCastor.fromAbnormalCasualty(params);
		abnormalCasualtyService.createAbnormalCasualty(entity);
		return entity.getAbnormalCasualtyId().toString();
	}

	@Transactional
	@Override
	public void consentAbnormalCasualty(Long abnormalCasualtyId) {
		AbnormalCasualtyEntity persist = abnormalCasualtyService.inquireAbnormalCasualty(abnormalCasualtyId);
		confirmAuthenticat(persist);

		if (persist.getIndemnity() != null && persist.getIndemnity()) {
			AbnormalExpenseEntity expense = createAbnormalSourceExpense(persist);
			persist.setVoucher(expense.getVoucher());
		}
		abnormalCasualtyService.renovateAbnormalCasualty(persist);
	}

	@Override
	public AbnormalCasualtyDetail inquireAbnormalCasualtyDetail(Long abnormalCasualtyId) {
		AbnormalCasualtyEntity abnormalCasualty = abnormalCasualtyService.inquireAbnormalCasualty(abnormalCasualtyId);
		return AbnormalCastor.toAbnormalCasualty(abnormalCasualty);
	}

	@Transactional
	@Override
	public String createAbnormalEquipment(AbnormalEquipment params) {
		AbnormalEquipmentEntity entity = AbnormalCastor.fromAbnormalEquipment(params);
		abnormalEquipmentService.createAbnormalEquipment(entity);
		return entity.getAbnormalEquipmentId().toString();
	}

	@Transactional
	@Override
	public void consentAbnormalEquipment(Long abnormalEquipmentId) {
		AbnormalEquipmentEntity persist = abnormalEquipmentService.inquireAbnormalEquipment(abnormalEquipmentId);
		confirmAuthenticat(persist);
		if (persist.getIndemnity() != null && persist.getIndemnity()) {
			AbnormalExpenseEntity expense = createAbnormalSourceExpense(persist);
			persist.setVoucher(expense.getVoucher());
		}
		abnormalEquipmentService.renovateAbnormalEquipment(persist);
	}

	@Override
	public AbnormalEquipmentDetail inquireAbnormalEquipmentDetail(Long abnormalEquipmentId) {
		AbnormalEquipmentEntity abnormalEquipment = abnormalEquipmentService.inquireAbnormalEquipment(abnormalEquipmentId);
		return AbnormalCastor.toAbnormalEquipment(abnormalEquipment);
	}

	@Transactional
	@Override
	public String createAbnormalRisk(AbnormalRisk params) {
		AbnormalRiskEntity entity = AbnormalCastor.fromAbnormalRisk(params);
		abnormalRiskService.createAbnormalRisk(entity);

		AbnormalEntity abnormal = abnormalService.inquireAbnormal(params.getAbnormalId());
		abnormal.setRiskEnabled(Boolean.TRUE);
		abnormalService.renovateAbnormal(abnormal);

		return entity.getAbnormalRiskId().toString();
	}

	@Transactional
	@Override
	public void consentAbnormalRisk(Long abnormalRiskId) {
		AbnormalRiskEntity persist = abnormalRiskService.inquireAbnormalRisk(abnormalRiskId);
		confirmAuthenticat(persist);
		abnormalRiskService.renovateAbnormalRisk(persist);
	}

	@Override
	@Transactional
	public void settlementAbnormalRisk(Long abnormalRiskId, Integer settlementState, String settlementMeasure, String settlementDetail, String operator, Date operatorTime) {
		AbnormalRiskEntity persist = abnormalRiskService.inquireAbnormalRisk(abnormalRiskId);
		if (persist.getSettlementState() != null && persist.getSettlementState().ordinal() > 0) {
			throw new BusinessException("该风险已处理！");
		}
		persist.setOperator(operator);
		persist.setOperatorTime(operatorTime);
		persist.setSettlementDetail(settlementDetail);
		persist.setSettlementMeasure(settlementMeasure);
		persist.setSettlementState(SettlementStateEnum.valueOf(settlementState));
		abnormalRiskService.renovateAbnormalRisk(persist);
	}

	@Override
	public AbnormalRiskDetail inquireAbnormalRiskDetail(Long abnormalRiskId) {
		AbnormalRiskEntity abnormalRisk = abnormalRiskService.inquireAbnormalRisk(abnormalRiskId);
		return AbnormalCastor.toAbnormalRisk(abnormalRisk);
	}

	@Override
	public PageList<AbnormalRiskDetail> inquireAbnormalRiskPageList(Long abnormalRiskId, Integer settlementState, PageCriteria page) {
		PageList<AbnormalRiskEntity> pages;
		if (settlementState == null || settlementState == 0) {
			pages = abnormalRiskService.inquireAbnormalRiskPageList(abnormalRiskId, 1, SettlementStateEnum.UNKNOWN, page);
		} else if (settlementState == 1) {
			pages = abnormalRiskService.inquireAbnormalRiskSettledPageList(abnormalRiskId, 1, page);
		} else {
			return null;
		}
		PageList<AbnormalRiskDetail> results = new PageList<AbnormalRiskDetail>(page, pages.getTotalRecordCount());
		for (AbnormalRiskEntity are : pages) {
			AbnormalRiskDetail detail = AbnormalCastor.toAbnormalRisk(are);
			results.add(detail);
		}
		return results;
	}

	@Transactional
	@Override
	public String createAbnormalExpense(AbnormalExpense params) {
		AbnormalExpenseEntity entity = AbnormalCastor.fromAbnormalExpense(params);
		abnormalExpenseService.createAbnormalExpense(entity);
		return entity.getAbnormalExpenseId().toString();
	}

	@Transactional
	@Override
	public void consentAbnormalExpense(Long abnormalExpenseId) {
		AbnormalExpenseEntity persist = abnormalExpenseService.inquireAbnormalExpense(abnormalExpenseId);
		confirmAuthenticat(persist);
		abnormalExpenseService.renovateAbnormalExpense(persist);

		// 生成收付款单
		AbnormalEntity abnormal = abnormalService.inquireAbnormal(persist.getAbnormalId());
		FinanceMoneyStatementEntity moneyEntity = FinanceLoanCastor.fromAbnormalExpense(abnormal, persist);
		financeMoneyStatementService.createFinanceMoneyStatement(moneyEntity);
	}

	@Override
	public AbnormalExpenseDetail inquireAbnormalExpenseDetail(Long abnormalExpenseId) {
		AbnormalExpenseEntity abnormalExpense = abnormalExpenseService.inquireAbnormalExpense(abnormalExpenseId);
		return AbnormalCastor.toAbnormalExpense(abnormalExpense);
	}

	@Transactional
	@Override
	public void normalAbnormalInventory(Long abnormalInventoryId, Integer reson, String handleDate, String handleRemark) {
		AbnormalInventoryEntity abnormalInventory = abnormalInventoryService.inquireAbnormalInventory(abnormalInventoryId);
		if (AbnormalResultEnum.UNKNOWN != abnormalInventory.getAbnormalResult()) {
			throw new BusinessException("该异常货箱已经被处置");
		}
		abnormalInventory.setAbnormalResult(AbnormalResultEnum.NORMAL);
		abnormalInventory.setHandleDate(DateUtil.parseDateInt(handleDate));
		abnormalInventory.setHandleRemark(handleRemark);
		abnormalInventory.setReson(reson);
		abnormalInventoryService.renovateAbnormalInventory(abnormalInventory);
		ContainerInventoryEntity inventory = containerInventoryService.inquireContainerInventory(abnormalInventory.getInventoryId());
		inventory.setDetainedState(Boolean.FALSE);
		inventory.setAbnormal(Boolean.TRUE);
		inventory.setLatestAbnormalResult(abnormalInventory.getAbnormalResult());
		inventory.setSupervisionState(SupervisionStateEnum.ALREADY_SUPERVISE);
		containerInventoryService.renovateContainerInventory(inventory);
		if (inventory.getConfirmationId() == null) {
			superviseContainerInventory(new Long[] { inventory.getInventoryId() }, true, null);
		} else {
			financeBulkstockService.calculateSupervisionFinanceBulkstock(inventory.getFinanceId());
			financeBulkstockService.calculateIncustodyFinanceBulkstock(inventory.getFinanceId());
			financeBulkstockService.calculateAbnormalFinanceBulkstock(inventory.getFinanceId());
		}
	}

	@Transactional
	@Override
	public void adjustAbnormalInventory(Long abnormalInventoryId, BigDecimal inventoryFinanceAmount, Integer reson, String handleDate, String handleRemark) {
		AbnormalInventoryEntity abnormalInventory = abnormalInventoryService.inquireAbnormalInventory(abnormalInventoryId);
		if (AbnormalResultEnum.UNKNOWN != abnormalInventory.getAbnormalResult()) {
			throw new BusinessException("该异常货箱已经处理完毕");
		}
		abnormalInventory.setAbnormalResult(AbnormalResultEnum.ADJUST);
		abnormalInventory.setTargetFinanceAmount(inventoryFinanceAmount);
		abnormalInventory.setHandleDate(DateUtil.parseDateInt(handleDate));
		abnormalInventory.setHandleRemark(handleRemark);
		abnormalInventory.setReson(reson);
		ContainerInventoryEntity inventory = containerInventoryService.inquireContainerInventory(abnormalInventory.getInventoryId());
		inventory.setDetainedState(Boolean.FALSE);
		inventory.setAbnormal(Boolean.TRUE);
		inventory.setLatestAbnormalResult(abnormalInventory.getAbnormalResult());
		BigDecimal sourceFinanceAmount = BigDecimal.ZERO;
		List<ContainerBulkstockEntity> bulkstocks = containerBulkstockService.inquireContainerBulkstockList(inventory.getInventoryId());
		for (ContainerBulkstockEntity cbe : bulkstocks) {
			sourceFinanceAmount = sourceFinanceAmount.add(cbe.getValuationFinanceAmount());
		}
		sourceFinanceAmount = sourceFinanceAmount.add(inventory.getAdjustment());
		abnormalInventory.setSourceFinanceAmount(sourceFinanceAmount);

		inventory.setAdjustment(abnormalInventory.getTargetFinanceAmount().subtract(sourceFinanceAmount));
		containerInventoryService.renovateContainerInventory(inventory);
		FinanceApplicationEntity finance = financeApplicationService.inquireFinanceApplicationEntity(inventory.getFinanceId());
		finance.setFinanceAmount(finance.getFinanceAmount().add(abnormalInventory.getTargetFinanceAmount()).subtract(abnormalInventory.getSourceFinanceAmount()));
		financeApplicationService.renovateFinanceApplication(finance);

		abnormalInventoryService.renovateAbnormalInventory(abnormalInventory);
		financeBulkstockService.calculateSupervisionFinanceBulkstock(inventory.getFinanceId());
		financeBulkstockService.calculateIncustodyFinanceBulkstock(inventory.getFinanceId());
		financeBulkstockService.calculateAbnormalFinanceBulkstock(inventory.getFinanceId());
	}

	@Transactional
	@Override
	public void exchangeAbnormalInventory(Long abnormalInventoryId, String targetCaseNumber, String targetFacingSlip, String targetFacingSlipNext, String exchangeDate, Long logisticsCompanyId, String logisticsCompanyName) {
		AbnormalInventoryEntity abnormalInventory = abnormalInventoryService.inquireAbnormalInventory(abnormalInventoryId);
		if (AbnormalResultEnum.UNKNOWN != abnormalInventory.getAbnormalResult()) {
			throw new BusinessException("该异常货箱已经处理完毕");
		}
		abnormalInventory.setAbnormalResult(AbnormalResultEnum.EXCHANGE);
		abnormalInventory.setTargetCaseNumber(targetCaseNumber);
		abnormalInventory.setTargetFacingSlip(targetFacingSlipNext);
		abnormalInventory.setTargetFacingSlipNext(targetFacingSlipNext);
		abnormalInventory.setHandleDate(DateUtil.parseDateInt(exchangeDate));

		ContainerInventoryEntity inventory = containerInventoryService.inquireContainerInventory(abnormalInventory.getInventoryId());
		abnormalInventory.setSourceCaseNumber(inventory.getCaseNumber());
		abnormalInventory.setSourceFacingSlip(inventory.getFacingSlip());
		abnormalInventory.setSourceFacingSlipNext(inventory.getFacingSlipNext());

		inventory.setDetainedState(Boolean.FALSE);
		inventory.setAbnormal(Boolean.TRUE);
		inventory.setLatestAbnormalResult(abnormalInventory.getAbnormalResult());
		inventory.setCaseNumber(abnormalInventory.getTargetCaseNumber());
		inventory.setFacingSlip(targetFacingSlip);
		inventory.setFacingSlipNext(targetFacingSlipNext);
		if (abnormalInventory.getTargetCaseNumber().equals(abnormalInventory.getSourceCaseNumber())) {
			throw new BusinessException("调换的货箱号不能与原货箱号相同");
		}

		containerInventoryService.renovateContainerInventory(inventory);
		abnormalInventoryService.renovateAbnormalInventory(abnormalInventory);

		if (SupervisionStateEnum.ALREADY_REPORT == inventory.getSupervisionState() || SupervisionStateEnum.UNKNOWN == inventory.getSupervisionState()) {
			FinanceBulkstockNoticeActionApi financeBulkstockNoticeAction = ComponentFactory.loadClass(FinanceBulkstockNoticeActionApi.class);
			Long[] inventoryIds = new Long[] { inventory.getInventoryId() };
			financeBulkstockNoticeAction.createRepeatRecieveNotice(inventory.getFinanceId(), inventoryIds, logisticsCompanyId, logisticsCompanyName, "换箱理货");
		}
	}

	@Transactional
	@Override
	public void returnAbnormalInventory(Long abnormalInventoryId, Integer reson, String handleDate, String handleRemark) {
		AbnormalInventoryEntity abnormalInventory = abnormalInventoryService.inquireAbnormalInventory(abnormalInventoryId);
		if (AbnormalResultEnum.UNKNOWN != abnormalInventory.getAbnormalResult()) {
			throw new BusinessException("该异常货箱已经处理完毕");
		}
		ContainerInventoryEntity inventory = containerInventoryService.inquireContainerInventory(abnormalInventory.getInventoryId());
		if (inventory.getLoanNoticeId() != null) {
			throw new BusinessException("该异常货箱已经放款");
		}
		abnormalInventory.setAbnormalResult(AbnormalResultEnum.RETURN);
		abnormalInventory.setHandleDate(DateUtil.parseDateInt(handleDate));
		abnormalInventory.setHandleRemark(handleRemark);
		abnormalInventory.setReson(reson);
		inventory.setLatestAbnormalResult(abnormalInventory.getAbnormalResult());
		inventory.setSupervisionState(SupervisionStateEnum.RETURN);

		BigDecimal sourceFinanceAmount = BigDecimal.ZERO;
		List<ContainerBulkstockEntity> bulkstocks = containerBulkstockService.inquireContainerBulkstockList(inventory.getInventoryId());
		for (ContainerBulkstockEntity cbe : bulkstocks) {
			sourceFinanceAmount = sourceFinanceAmount.add(cbe.getValuationFinanceAmount());
			FinanceBulkstockEntity bulkstock = financeBulkstockService.inquireFinanceBulkstock(cbe.getBulkstockId());
			bulkstock.setQuantity(bulkstock.getQuantity().subtract(cbe.getQuantity()));
			bulkstock.setWeight(bulkstock.getWeight().subtract(cbe.getWeight()));
			bulkstock.setVolume(bulkstock.getVolume().subtract(cbe.getVolume()));
			bulkstock.setValuationQuantity(bulkstock.getValuationQuantity().subtract(cbe.getValuationQuantity()));
			financeBulkstockService.renovateFinanceBulkstock(bulkstock);
		}
		sourceFinanceAmount = sourceFinanceAmount.add(inventory.getAdjustment());
		abnormalInventory.setSourceFinanceAmount(sourceFinanceAmount);
		FinanceApplicationEntity finance = financeApplicationService.inquireFinanceApplicationEntity(inventory.getFinanceId());
		finance.setFinanceAmount(finance.getFinanceAmount().subtract(abnormalInventory.getSourceFinanceAmount()));
		financeApplicationService.renovateFinanceApplication(finance);

		containerInventoryService.renovateContainerInventory(inventory);
		abnormalInventoryService.renovateAbnormalInventory(abnormalInventory);

		// 扣减箱量
		FinanceContainerEntity financeContainer = financeContainerService.inquireFinanceContainer(inventory.getFinanceId());
		if (financeContainer != null && financeContainer.getCaseQuantity() != null && financeContainer.getCaseQuantity() > 0) {
			financeContainer.setCaseQuantity(financeContainer.getCaseQuantity() - 1);
			financeContainerService.renovateFinanceContainer(financeContainer);
		}
	}

	@Transactional
	@Override
	public void handleAbnormalInventory(Long abnormalInventoryId, Integer reson, String handleDate, String handleRemark) {
		AbnormalInventoryEntity abnormalInventory = abnormalInventoryService.inquireAbnormalInventory(abnormalInventoryId);
		if (AbnormalResultEnum.UNKNOWN != abnormalInventory.getAbnormalResult()) {
			throw new BusinessException("该异常货箱已经处理完毕");
		}
		abnormalInventory.setAbnormalResult(AbnormalResultEnum.HANDLE);
		abnormalInventory.setHandleDate(DateUtil.parseDateInt(handleDate));
		abnormalInventory.setHandleRemark(handleRemark);
		abnormalInventory.setReson(reson);

		ContainerInventoryEntity inventory = containerInventoryService.inquireContainerInventory(abnormalInventory.getInventoryId());
		inventory.setLatestAbnormalResult(abnormalInventory.getAbnormalResult());
		inventory.setSupervisionState(SupervisionStateEnum.RELIEVE_SUPERVISE);
		inventory.setBadassetsState(BadassetsStateEnum.BADASSETS);
		containerInventoryService.renovateContainerInventory(inventory);

		// 直接处置生成解除质押单
		ContainerInventoryRelieveEntity relieve = new ContainerInventoryRelieveEntity();
		relieve.setInventoryId(inventory.getInventoryId());
		relieve.setRelieveAccountId(FinanceSessionContext.getAccountId());
		relieve.setRelieveAccountor(FinanceSessionContext.getAccountFullName());
		relieve.setRelieveRemark(handleRemark);
		containerInventoryRelieveService.createContainerInventoryRelieve(relieve);
		// 项目动态
		FinanceProcessEntity processEntity = FinanceProcessCastor.fromFinanceRelieveProcess(inventory, true);
		if (!LongUtils.isPrimaryKey(processEntity.getProcessId())) {
			financeProcessService.createFinanceProcess(processEntity);
		} else {
			financeProcessService.renovateFinanceProcess(processEntity);
		}
		processEntity.getCurrentDetail().setProcessId(processEntity.getProcessId());
		financeProcessDetailService.createFinanceProcessDetail(processEntity.getCurrentDetail());
	}

	@Override
	public PageList<AbnormalTrackDetail> inquireAbnormalTaskPageList(Long abnormalId, PageCriteria page) {
		PageList<AbnormalTrackEntity> pages = abnormalTrackService.inquireAbnormalTrackPageList(abnormalId, page);
		PageList<AbnormalTrackDetail> results = new PageList<>(page, pages.getTotalRecordCount());
		for (AbnormalTrackEntity e : pages) {
			results.add(AbnormalCastor.toAbnormalTrack(e));
		}
		return results;
	}

	@Override
	public AbnormalDetail inquireAbnormalDetail(Long abnormalId) {
		AbnormalEntity abnormal = abnormalService.inquireAbnormal(abnormalId);
		return AbnormalCastor.toAbnormalDetail(abnormal);
	}

	@Override
	public PageList<AbnormalLineInfo> inquireAbnormalPageList(Long[] abnormalIds, Long enterpriseId, Long financeId, Integer handleState, String startDate, String endDate, String financeNumber, Integer abnormalState, PageCriteria page) {
		if (FinanceSessionContext.isEnterprise()) {
			enterpriseId = FinanceSessionContext.getEnterpriseId();
		}
		HandleStateEnum _state = null;
		if (handleState != null) {
			_state = HandleStateEnum.valueOf(handleState);
		}
		PageList<AbnormalEntity> pages = abnormalService.inquireAbnormalPageList(abnormalIds, enterpriseId, financeId, _state, startDate, endDate, financeNumber, abnormalState, page);
		PageList<AbnormalLineInfo> results = new PageList<>(page, pages.getTotalRecordCount());
		for (AbnormalEntity dae : pages) {
			results.add(AbnormalCastor.toAbnormalLineInfo(dae));
		}
		return results;
	}
}
